{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import matplotlib\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "100\n",
      "200\n",
      "300\n",
      "400\n",
      "500\n",
      "600\n",
      "700\n",
      "800\n",
      "900\n",
      "1000\n",
      "1100\n",
      "1200\n",
      "1300\n",
      "1400\n",
      "1500\n",
      "1600\n",
      "1700\n",
      "1800\n",
      "1900\n",
      "2000\n",
      "2100\n",
      "2200\n",
      "2300\n",
      "2400\n",
      "2500\n",
      "2600\n",
      "2700\n",
      "2800\n",
      "2900\n",
      "3000\n",
      "3100\n",
      "3200\n",
      "3300\n",
      "3400\n",
      "3500\n",
      "3600\n",
      "3700\n",
      "3800\n",
      "3900\n",
      "4000\n",
      "4100\n",
      "4200\n",
      "4300\n",
      "4400\n",
      "4500\n",
      "4600\n",
      "4700\n",
      "4800\n",
      "4900\n",
      "5000\n",
      "5100\n",
      "5200\n",
      "5300\n",
      "5400\n",
      "5500\n",
      "5600\n",
      "5700\n",
      "5800\n",
      "5900\n",
      "6000\n",
      "6100\n",
      "6200\n",
      "6300\n",
      "6400\n"
     ]
    }
   ],
   "source": [
    "import deepchem as dc\n",
    "import deepchem\n",
    "from rdkit import Chem\n",
    "import numpy as np\n",
    "import os\n",
    "import pickle\n",
    "from deepchem.contrib.torch.pytorch_graphconv import symmetric_normalize_adj\n",
    "np.random.seed(2017)\n",
    "\n",
    "\n",
    "# Load Tox21 dataset\n",
    "save_file = \"./tox21_featurized_nxn.pkl\"\n",
    "if not os.path.exists(save_file):\n",
    "#if 1==1:\n",
    "    tox21_tasks, tox21_datasets, transformers = dc.molnet.load_tox21(featurizer=\"AdjacencyConv\")\n",
    "    with open(save_file, \"wb\") as f:\n",
    "        pickle.dump((tox21_tasks, tox21_datasets, transformers), f, protocol=2)\n",
    "else:\n",
    "    with open(save_file, \"rb\") as f:\n",
    "        tox21_tasks, tox21_datasets, transformers = pickle.load(f)\n",
    "train_dataset, valid_dataset, test_dataset = tox21_datasets\n",
    "\n",
    "train_dataset_x = train_dataset.X\n",
    "valid_dataset_x = valid_dataset.X\n",
    "test_dataset_x = test_dataset.X\n",
    "\n",
    "for idx in range(0, len(train_dataset_x)):\n",
    "    if idx % 100 == 0: print(idx)\n",
    "    train_dataset_x[idx] = {\"g\": symmetric_normalize_adj(train_dataset_x[idx][0]), \"x\": train_dataset_x[idx][1]}\n",
    "\n",
    "for idx in range(0, len(valid_dataset_x)):\n",
    "    valid_dataset_x[idx] = {\"g\": symmetric_normalize_adj(valid_dataset_x[idx][0]), \"x\": valid_dataset_x[idx][1]}\n",
    "\n",
    "for idx in range(0, len(test_dataset_x)):\n",
    "    test_dataset_x[idx] = {\"g\": symmetric_normalize_adj(test_dataset_x[idx][0]), \"x\": test_dataset_x[idx][1]}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(150, 150)"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_dataset_x[0][\"g\"].shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import deepchem.contrib.torch.pytorch_graphconv\n",
    "reload(deepchem.contrib.torch.pytorch_graphconv)\n",
    "from deepchem.contrib.torch.pytorch_graphconvpytorch_graphconv import GraphConvolution, SingleTaskGraphConvolution, MultiTaskGraphConvolution\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "GraphConvolution (\n",
      "  (conv_ops): ModuleList (\n",
      "    (0): Sequential (\n",
      "      (0): Linear (75 -> 128)\n",
      "      (1): Dropout (p = 0.0)\n",
      "      (2): LeakyReLU (0.01, inplace)\n",
      "      (3): BatchNorm1d(128, eps=1e-05, momentum=0.1, affine=True)\n",
      "    )\n",
      "  )\n",
      "  (fc_ops): ModuleList (\n",
      "    (0): Sequential (\n",
      "      (0): Linear (128 -> 64)\n",
      "      (1): Dropout (p = 0.0)\n",
      "      (2): ReLU (inplace)\n",
      "      (3): BatchNorm1d(64, eps=1e-05, momentum=0.1, affine=True)\n",
      "    )\n",
      "    (1): Sequential (\n",
      "      (0): Linear (64 -> 12)\n",
      "      (1): Dropout (p = 0.0)\n",
      "      (2): ReLU (inplace)\n",
      "      (3): BatchNorm1d(12, eps=1e-05, momentum=0.1, affine=True)\n",
      "    )\n",
      "  )\n",
      ")\n"
     ]
    }
   ],
   "source": [
    "gc = GraphConvolution(n_conv_layers=1,\n",
    "                     max_n_atoms=train_dataset_x[0][\"g\"].shape[0],\n",
    "                     n_atom_types=train_dataset_x[0][\"x\"].shape[1],\n",
    "                     max_valence=4,\n",
    "                     conv_layer_dims=[128,128,256],\n",
    "                     n_fc_layers=2,\n",
    "                     fc_layer_dims=[64, 12],\n",
    "                     dropout=0.,\n",
    "                     return_sigmoid=True)\n",
    "\n",
    "print(gc)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<pytorch_graphconv.MultiTaskGraphConvolution object at 0x7fe4d472fa50>\n"
     ]
    }
   ],
   "source": [
    "mtgc = MultiTaskGraphConvolution(net=gc, lr=1e-3, weight_decay=0., n_tasks=train_dataset.y.shape[1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "epoch: 0\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.53186988363\n",
      "ROC AUC:\n",
      "0.723114679447\n",
      "TEST:\n",
      "RMSE:\n",
      "0.528469609187\n",
      "ROC AUC:\n",
      "0.675233267089\n",
      "epoch: 1\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.598940708157\n",
      "ROC AUC:\n",
      "0.755874104233\n",
      "TEST:\n",
      "RMSE:\n",
      "0.590225975884\n",
      "ROC AUC:\n",
      "0.711647401725\n",
      "epoch: 2\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.562084877244\n",
      "ROC AUC:\n",
      "0.78211365085\n",
      "TEST:\n",
      "RMSE:\n",
      "0.556865888178\n",
      "ROC AUC:\n",
      "0.726447343016\n",
      "epoch: 3\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.642413079526\n",
      "ROC AUC:\n",
      "0.78587978098\n",
      "TEST:\n",
      "RMSE:\n",
      "0.634735195488\n",
      "ROC AUC:\n",
      "0.737737387723\n",
      "epoch: 4\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.638659640579\n",
      "ROC AUC:\n",
      "0.803120459635\n",
      "TEST:\n",
      "RMSE:\n",
      "0.629150083298\n",
      "ROC AUC:\n",
      "0.769429276589\n",
      "epoch: 5\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.582474446838\n",
      "ROC AUC:\n",
      "0.81245649018\n",
      "TEST:\n",
      "RMSE:\n",
      "0.572140395229\n",
      "ROC AUC:\n",
      "0.772381808464\n",
      "epoch: 6\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.704796795508\n",
      "ROC AUC:\n",
      "0.801768784871\n",
      "TEST:\n",
      "RMSE:\n",
      "0.695747050214\n",
      "ROC AUC:\n",
      "0.773810687118\n",
      "epoch: 7\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.685908526704\n",
      "ROC AUC:\n",
      "0.823920923992\n",
      "TEST:\n",
      "RMSE:\n",
      "0.677127303167\n",
      "ROC AUC:\n",
      "0.772956146258\n",
      "epoch: 8\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.659291154141\n",
      "ROC AUC:\n",
      "0.818992835694\n",
      "TEST:\n",
      "RMSE:\n",
      "0.65217092742\n",
      "ROC AUC:\n",
      "0.781351347957\n",
      "epoch: 9\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.671502161027\n",
      "ROC AUC:\n",
      "0.810644545312\n",
      "TEST:\n",
      "RMSE:\n",
      "0.660665267729\n",
      "ROC AUC:\n",
      "0.763459361922\n",
      "epoch: 10\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.700032647626\n",
      "ROC AUC:\n",
      "0.810779775378\n",
      "TEST:\n",
      "RMSE:\n",
      "0.69290967366\n",
      "ROC AUC:\n",
      "0.761431912225\n",
      "epoch: 11\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.767156844417\n",
      "ROC AUC:\n",
      "0.811739557383\n",
      "TEST:\n",
      "RMSE:\n",
      "0.758572523042\n",
      "ROC AUC:\n",
      "0.764784832302\n",
      "epoch: 12\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.753884446232\n",
      "ROC AUC:\n",
      "0.819315866735\n",
      "TEST:\n",
      "RMSE:\n",
      "0.743418487105\n",
      "ROC AUC:\n",
      "0.764869501505\n",
      "epoch: 13\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.718770698779\n",
      "ROC AUC:\n",
      "0.817167256792\n",
      "TEST:\n",
      "RMSE:\n",
      "0.711835244379\n",
      "ROC AUC:\n",
      "0.788994632188\n",
      "epoch: 14\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.724336389134\n",
      "ROC AUC:\n",
      "0.832878055325\n",
      "TEST:\n",
      "RMSE:\n",
      "0.715701222555\n",
      "ROC AUC:\n",
      "0.787385426772\n",
      "epoch: 15\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.747999631188\n",
      "ROC AUC:\n",
      "0.829874422947\n",
      "TEST:\n",
      "RMSE:\n",
      "0.741302864203\n",
      "ROC AUC:\n",
      "0.783744651026\n",
      "epoch: 16\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.749683401153\n",
      "ROC AUC:\n",
      "0.837899146847\n",
      "TEST:\n",
      "RMSE:\n",
      "0.743330795796\n",
      "ROC AUC:\n",
      "0.799209093492\n",
      "epoch: 17\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.789491601515\n",
      "ROC AUC:\n",
      "0.838638054584\n",
      "TEST:\n",
      "RMSE:\n",
      "0.780108520322\n",
      "ROC AUC:\n",
      "0.785109169312\n",
      "epoch: 18\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.794947192656\n",
      "ROC AUC:\n",
      "0.829175652813\n",
      "TEST:\n",
      "RMSE:\n",
      "0.789303090961\n",
      "ROC AUC:\n",
      "0.784858791783\n",
      "epoch: 19\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.791379053443\n",
      "ROC AUC:\n",
      "0.834376097899\n",
      "TEST:\n",
      "RMSE:\n",
      "0.785039878347\n",
      "ROC AUC:\n",
      "0.782490310625\n",
      "epoch: 20\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.790213421906\n",
      "ROC AUC:\n",
      "0.84486576613\n",
      "TEST:\n",
      "RMSE:\n",
      "0.783333710333\n",
      "ROC AUC:\n",
      "0.792433496903\n",
      "epoch: 21\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.776783335309\n",
      "ROC AUC:\n",
      "0.840139980925\n",
      "TEST:\n",
      "RMSE:\n",
      "0.77025888597\n",
      "ROC AUC:\n",
      "0.795943982149\n",
      "epoch: 22\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.782282614857\n",
      "ROC AUC:\n",
      "0.841350465749\n",
      "TEST:\n",
      "RMSE:\n",
      "0.777188343188\n",
      "ROC AUC:\n",
      "0.792490400887\n",
      "epoch: 23\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.819948831147\n",
      "ROC AUC:\n",
      "0.844551760251\n",
      "TEST:\n",
      "RMSE:\n",
      "0.815227094932\n",
      "ROC AUC:\n",
      "0.781483110113\n",
      "epoch: 24\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.805488880979\n",
      "ROC AUC:\n",
      "0.823387590349\n",
      "TEST:\n",
      "RMSE:\n",
      "0.797630158931\n",
      "ROC AUC:\n",
      "0.779858501377\n",
      "epoch: 25\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.854889571883\n",
      "ROC AUC:\n",
      "0.818578959239\n",
      "TEST:\n",
      "RMSE:\n",
      "0.852101354073\n",
      "ROC AUC:\n",
      "0.753321720996\n",
      "epoch: 26\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.817167701228\n",
      "ROC AUC:\n",
      "0.84299811066\n",
      "TEST:\n",
      "RMSE:\n",
      "0.813433980716\n",
      "ROC AUC:\n",
      "0.779987025892\n",
      "epoch: 27\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.84590004396\n",
      "ROC AUC:\n",
      "0.844080048939\n",
      "TEST:\n",
      "RMSE:\n",
      "0.842470858171\n",
      "ROC AUC:\n",
      "0.789743802568\n",
      "epoch: 28\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.83433587212\n",
      "ROC AUC:\n",
      "0.84903604871\n",
      "TEST:\n",
      "RMSE:\n",
      "0.830326107974\n",
      "ROC AUC:\n",
      "0.795776998389\n",
      "epoch: 29\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.833986482866\n",
      "ROC AUC:\n",
      "0.852971315268\n",
      "TEST:\n",
      "RMSE:\n",
      "0.83034489568\n",
      "ROC AUC:\n",
      "0.798362597679\n",
      "epoch: 30\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.860026995721\n",
      "ROC AUC:\n",
      "0.839949677824\n",
      "TEST:\n",
      "RMSE:\n",
      "0.857066908998\n",
      "ROC AUC:\n",
      "0.775130172768\n",
      "epoch: 31\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.847605611651\n",
      "ROC AUC:\n",
      "0.851982281002\n",
      "TEST:\n",
      "RMSE:\n",
      "0.844974399196\n",
      "ROC AUC:\n",
      "0.794970041034\n",
      "epoch: 32\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.854665903194\n",
      "ROC AUC:\n",
      "0.851502578936\n",
      "TEST:\n",
      "RMSE:\n",
      "0.852252192472\n",
      "ROC AUC:\n",
      "0.791160221211\n",
      "epoch: 33\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.862152987779\n",
      "ROC AUC:\n",
      "0.84607879539\n",
      "TEST:\n",
      "RMSE:\n",
      "0.86036796003\n",
      "ROC AUC:\n",
      "0.779487644379\n",
      "epoch: 34\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.859375767801\n",
      "ROC AUC:\n",
      "0.853598858699\n",
      "TEST:\n",
      "RMSE:\n",
      "0.854968626042\n",
      "ROC AUC:\n",
      "0.7845451331\n",
      "epoch: 35\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.869298698531\n",
      "ROC AUC:\n",
      "0.854877828829\n",
      "TEST:\n",
      "RMSE:\n",
      "0.864919059602\n",
      "ROC AUC:\n",
      "0.7917297516\n",
      "epoch: 36\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.869651776755\n",
      "ROC AUC:\n",
      "0.855105576283\n",
      "TEST:\n",
      "RMSE:\n",
      "0.865064118839\n",
      "ROC AUC:\n",
      "0.798612582766\n",
      "epoch: 37\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.886879476241\n",
      "ROC AUC:\n",
      "0.855505081926\n",
      "TEST:\n",
      "RMSE:\n",
      "0.885691688422\n",
      "ROC AUC:\n",
      "0.800056766629\n",
      "epoch: 38\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.871914537234\n",
      "ROC AUC:\n",
      "0.849655303757\n",
      "TEST:\n",
      "RMSE:\n",
      "0.868528931363\n",
      "ROC AUC:\n",
      "0.793178154207\n",
      "epoch: 39\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.867837743555\n",
      "ROC AUC:\n",
      "0.849937208016\n",
      "TEST:\n",
      "RMSE:\n",
      "0.864016387228\n",
      "ROC AUC:\n",
      "0.795752863251\n",
      "epoch: 40\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.857926416644\n",
      "ROC AUC:\n",
      "0.837417886605\n",
      "TEST:\n",
      "RMSE:\n",
      "0.855494448824\n",
      "ROC AUC:\n",
      "0.796943137615\n",
      "epoch: 41\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.894374857055\n",
      "ROC AUC:\n",
      "0.843325575498\n",
      "TEST:\n",
      "RMSE:\n",
      "0.892262398245\n",
      "ROC AUC:\n",
      "0.789975931577\n",
      "epoch: 42\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.890075166468\n",
      "ROC AUC:\n",
      "0.852815544425\n",
      "TEST:\n",
      "RMSE:\n",
      "0.889214264798\n",
      "ROC AUC:\n",
      "0.78515518305\n",
      "epoch: 43\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.892523775966\n",
      "ROC AUC:\n",
      "0.859971686262\n",
      "TEST:\n",
      "RMSE:\n",
      "0.889855235803\n",
      "ROC AUC:\n",
      "0.796565609116\n",
      "epoch: 44\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.894561573761\n",
      "ROC AUC:\n",
      "0.861110406025\n",
      "TEST:\n",
      "RMSE:\n",
      "0.892693982821\n",
      "ROC AUC:\n",
      "0.801407451361\n",
      "epoch: 45\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.895778291671\n",
      "ROC AUC:\n",
      "0.864573838719\n",
      "TEST:\n",
      "RMSE:\n",
      "0.893402096689\n",
      "ROC AUC:\n",
      "0.807178103975\n",
      "epoch: 46\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.901926233982\n",
      "ROC AUC:\n",
      "0.858844375611\n",
      "TEST:\n",
      "RMSE:\n",
      "0.900232845846\n",
      "ROC AUC:\n",
      "0.8054827577\n",
      "epoch: 47\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.90112203259\n",
      "ROC AUC:\n",
      "0.860794426165\n",
      "TEST:\n",
      "RMSE:\n",
      "0.899489209332\n",
      "ROC AUC:\n",
      "0.799393050336\n",
      "epoch: 48\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.906220887096\n",
      "ROC AUC:\n",
      "0.865673990726\n",
      "TEST:\n",
      "RMSE:\n",
      "0.903847771065\n",
      "ROC AUC:\n",
      "0.808401245295\n",
      "epoch: 49\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.908549273683\n",
      "ROC AUC:\n",
      "0.86483991466\n",
      "TEST:\n",
      "RMSE:\n",
      "0.906795882571\n",
      "ROC AUC:\n",
      "0.7979263011\n",
      "epoch: 50\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.913077018159\n",
      "ROC AUC:\n",
      "0.867931245462\n",
      "TEST:\n",
      "RMSE:\n",
      "0.911690965412\n",
      "ROC AUC:\n",
      "0.80672120423\n",
      "epoch: 51\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.910657974465\n",
      "ROC AUC:\n",
      "0.853133264831\n",
      "TEST:\n",
      "RMSE:\n",
      "0.907812835612\n",
      "ROC AUC:\n",
      "0.792085990161\n",
      "epoch: 52\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.914595355296\n",
      "ROC AUC:\n",
      "0.855434915892\n",
      "TEST:\n",
      "RMSE:\n",
      "0.912994891771\n",
      "ROC AUC:\n",
      "0.779533658118\n",
      "epoch: 53\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.904838862712\n",
      "ROC AUC:\n",
      "0.860277297254\n",
      "TEST:\n",
      "RMSE:\n",
      "0.902881918376\n",
      "ROC AUC:\n",
      "0.80415100826\n",
      "epoch: 54\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.916614034918\n",
      "ROC AUC:\n",
      "0.854245365766\n",
      "TEST:\n",
      "RMSE:\n",
      "0.915204816861\n",
      "ROC AUC:\n",
      "0.794301713556\n",
      "epoch: 55\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.920304433292\n",
      "ROC AUC:\n",
      "0.843420751121\n",
      "TEST:\n",
      "RMSE:\n",
      "0.918212983712\n",
      "ROC AUC:\n",
      "0.785868739384\n",
      "epoch: 56\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.92549607619\n",
      "ROC AUC:\n",
      "0.843905393245\n",
      "TEST:\n",
      "RMSE:\n",
      "0.923702627051\n",
      "ROC AUC:\n",
      "0.79529105799\n",
      "epoch: 57\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.920326548937\n",
      "ROC AUC:\n",
      "0.855349356311\n",
      "TEST:\n",
      "RMSE:\n",
      "0.917578781078\n",
      "ROC AUC:\n",
      "0.80014379048\n",
      "epoch: 58\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.918235023484\n",
      "ROC AUC:\n",
      "0.858402225861\n",
      "TEST:\n",
      "RMSE:\n",
      "0.915700849948\n",
      "ROC AUC:\n",
      "0.798753567291\n",
      "epoch: 59\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.923372252821\n",
      "ROC AUC:\n",
      "0.852344962353\n",
      "TEST:\n",
      "RMSE:\n",
      "0.922896909112\n",
      "ROC AUC:\n",
      "0.797422897064\n",
      "epoch: 60\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.920716157336\n",
      "ROC AUC:\n",
      "0.846140102585\n",
      "TEST:\n",
      "RMSE:\n",
      "0.920963904548\n",
      "ROC AUC:\n",
      "0.788893578562\n",
      "epoch: 61\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.920366277151\n",
      "ROC AUC:\n",
      "0.854903023707\n",
      "TEST:\n",
      "RMSE:\n",
      "0.920194833465\n",
      "ROC AUC:\n",
      "0.808726971546\n",
      "epoch: 62\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.926801732535\n",
      "ROC AUC:\n",
      "0.859927874983\n",
      "TEST:\n",
      "RMSE:\n",
      "0.926253023518\n",
      "ROC AUC:\n",
      "0.801274511882\n",
      "epoch: 63\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.926582790221\n",
      "ROC AUC:\n",
      "0.864419491826\n",
      "TEST:\n",
      "RMSE:\n",
      "0.925949254929\n",
      "ROC AUC:\n",
      "0.807576529972\n",
      "epoch: 64\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.931422508418\n",
      "ROC AUC:\n",
      "0.855404230926\n",
      "TEST:\n",
      "RMSE:\n",
      "0.931795863437\n",
      "ROC AUC:\n",
      "0.790034307216\n",
      "epoch: 65\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.928686837991\n",
      "ROC AUC:\n",
      "0.857457358862\n",
      "TEST:\n",
      "RMSE:\n",
      "0.929081629356\n",
      "ROC AUC:\n",
      "0.793033932042\n",
      "epoch: 66\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.931913446688\n",
      "ROC AUC:\n",
      "0.860368834217\n",
      "TEST:\n",
      "RMSE:\n",
      "0.932202917079\n",
      "ROC AUC:\n",
      "0.802801893294\n",
      "epoch: 67\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.93074883291\n",
      "ROC AUC:\n",
      "0.859710499316\n",
      "TEST:\n",
      "RMSE:\n",
      "0.930041598504\n",
      "ROC AUC:\n",
      "0.797978103347\n",
      "epoch: 68\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.930061635495\n",
      "ROC AUC:\n",
      "0.864354573691\n",
      "TEST:\n",
      "RMSE:\n",
      "0.929510783324\n",
      "ROC AUC:\n",
      "0.800886681799\n",
      "epoch: 69\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.926299685943\n",
      "ROC AUC:\n",
      "0.865296090905\n",
      "TEST:\n",
      "RMSE:\n",
      "0.926035663576\n",
      "ROC AUC:\n",
      "0.797711733837\n",
      "epoch: 70\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.936108132936\n",
      "ROC AUC:\n",
      "0.844312896937\n",
      "TEST:\n",
      "RMSE:\n",
      "0.93649247942\n",
      "ROC AUC:\n",
      "0.77931153636\n",
      "epoch: 71\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.9309734069\n",
      "ROC AUC:\n",
      "0.855362592047\n",
      "TEST:\n",
      "RMSE:\n",
      "0.930042538452\n",
      "ROC AUC:\n",
      "0.794882722852\n",
      "epoch: 72\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.928986652152\n",
      "ROC AUC:\n",
      "0.819924243734\n",
      "TEST:\n",
      "RMSE:\n",
      "0.927448826211\n",
      "ROC AUC:\n",
      "0.767221892572\n",
      "epoch: 73\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "TRAIN:\n",
      "RMSE:\n",
      "0.935343863728\n",
      "ROC AUC:\n",
      "0.85891439429\n",
      "TEST:\n",
      "RMSE:\n",
      "0.93542656286\n",
      "ROC AUC:\n",
      "0.793173052471\n",
      "epoch: 74\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.939686779958\n",
      "ROC AUC:\n",
      "0.864057691692\n",
      "TEST:\n",
      "RMSE:\n",
      "0.939869228688\n",
      "ROC AUC:\n",
      "0.796912527196\n",
      "epoch: 75\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.935859721835\n",
      "ROC AUC:\n",
      "0.865996652648\n",
      "TEST:\n",
      "RMSE:\n",
      "0.935587767454\n",
      "ROC AUC:\n",
      "0.795789850841\n",
      "epoch: 76\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.927668072835\n",
      "ROC AUC:\n",
      "0.837019199442\n",
      "TEST:\n",
      "RMSE:\n",
      "0.926876897414\n",
      "ROC AUC:\n",
      "0.789698573711\n",
      "epoch: 77\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.937896748472\n",
      "ROC AUC:\n",
      "0.841826440158\n",
      "TEST:\n",
      "RMSE:\n",
      "0.938453850481\n",
      "ROC AUC:\n",
      "0.7903299136\n",
      "epoch: 78\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.940171536989\n",
      "ROC AUC:\n",
      "0.840430777579\n",
      "TEST:\n",
      "RMSE:\n",
      "0.9405977132\n",
      "ROC AUC:\n",
      "0.781582005312\n",
      "epoch: 79\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.94313998238\n",
      "ROC AUC:\n",
      "0.820048123048\n",
      "TEST:\n",
      "RMSE:\n",
      "0.943101489585\n",
      "ROC AUC:\n",
      "0.758384605785\n",
      "epoch: 80\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.943944238094\n",
      "ROC AUC:\n",
      "0.84294497659\n",
      "TEST:\n",
      "RMSE:\n",
      "0.944225736878\n",
      "ROC AUC:\n",
      "0.791365075553\n",
      "epoch: 81\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.941252839501\n",
      "ROC AUC:\n",
      "0.850100454599\n",
      "TEST:\n",
      "RMSE:\n",
      "0.941178139709\n",
      "ROC AUC:\n",
      "0.805032823788\n",
      "epoch: 82\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.94334845548\n",
      "ROC AUC:\n",
      "0.85880782998\n",
      "TEST:\n",
      "RMSE:\n",
      "0.942989117748\n",
      "ROC AUC:\n",
      "0.805144178997\n",
      "epoch: 83\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.942757197439\n",
      "ROC AUC:\n",
      "0.858633969422\n",
      "TEST:\n",
      "RMSE:\n",
      "0.942967791298\n",
      "ROC AUC:\n",
      "0.802188998145\n",
      "epoch: 84\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.941984003547\n",
      "ROC AUC:\n",
      "0.863459588728\n",
      "TEST:\n",
      "RMSE:\n",
      "0.94202779962\n",
      "ROC AUC:\n",
      "0.805272801623\n",
      "epoch: 85\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.943861135122\n",
      "ROC AUC:\n",
      "0.869559424854\n",
      "TEST:\n",
      "RMSE:\n",
      "0.944059712049\n",
      "ROC AUC:\n",
      "0.80357490448\n",
      "epoch: 86\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.943892160782\n",
      "ROC AUC:\n",
      "0.870380012782\n",
      "TEST:\n",
      "RMSE:\n",
      "0.944058229597\n",
      "ROC AUC:\n",
      "0.809208300761\n",
      "epoch: 87\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.940230995333\n",
      "ROC AUC:\n",
      "0.87246376003\n",
      "TEST:\n",
      "RMSE:\n",
      "0.939949200727\n",
      "ROC AUC:\n",
      "0.808967047492\n",
      "epoch: 88\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.944266292794\n",
      "ROC AUC:\n",
      "0.866078344511\n",
      "TEST:\n",
      "RMSE:\n",
      "0.944297956638\n",
      "ROC AUC:\n",
      "0.801329159328\n",
      "epoch: 89\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.946623793073\n",
      "ROC AUC:\n",
      "0.847425492164\n",
      "TEST:\n",
      "RMSE:\n",
      "0.947071148307\n",
      "ROC AUC:\n",
      "0.784504515429\n",
      "epoch: 90\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.937446099607\n",
      "ROC AUC:\n",
      "0.83987666243\n",
      "TEST:\n",
      "RMSE:\n",
      "0.937755393829\n",
      "ROC AUC:\n",
      "0.795186079951\n",
      "epoch: 91\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.945965778444\n",
      "ROC AUC:\n",
      "0.864741295877\n",
      "TEST:\n",
      "RMSE:\n",
      "0.946522999419\n",
      "ROC AUC:\n",
      "0.80281003645\n",
      "epoch: 92\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.945757927527\n",
      "ROC AUC:\n",
      "0.799365484756\n",
      "TEST:\n",
      "RMSE:\n",
      "0.945521591078\n",
      "ROC AUC:\n",
      "0.749642387895\n",
      "epoch: 93\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.948769988161\n",
      "ROC AUC:\n",
      "0.797458654599\n",
      "TEST:\n",
      "RMSE:\n",
      "0.949179327489\n",
      "ROC AUC:\n",
      "0.755016478609\n",
      "epoch: 94\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.95036789814\n",
      "ROC AUC:\n",
      "0.810493345408\n",
      "TEST:\n",
      "RMSE:\n",
      "0.951081825452\n",
      "ROC AUC:\n",
      "0.748300042541\n",
      "epoch: 95\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.946148022472\n",
      "ROC AUC:\n",
      "0.806541112539\n",
      "TEST:\n",
      "RMSE:\n",
      "0.946281742483\n",
      "ROC AUC:\n",
      "0.758772828309\n",
      "epoch: 96\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.942774428703\n",
      "ROC AUC:\n",
      "0.785112083474\n",
      "TEST:\n",
      "RMSE:\n",
      "0.942970572363\n",
      "ROC AUC:\n",
      "0.739490128532\n",
      "epoch: 97\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.948110874706\n",
      "ROC AUC:\n",
      "0.801159481428\n",
      "TEST:\n",
      "RMSE:\n",
      "0.948190755217\n",
      "ROC AUC:\n",
      "0.748907443512\n",
      "epoch: 98\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.950300825258\n",
      "ROC AUC:\n",
      "0.813960766914\n",
      "TEST:\n",
      "RMSE:\n",
      "0.950183085411\n",
      "ROC AUC:\n",
      "0.776723484313\n",
      "epoch: 99\n",
      "TRAIN:\n",
      "RMSE:\n",
      "0.953419139379\n",
      "ROC AUC:\n",
      "0.822994361177\n",
      "TEST:\n",
      "RMSE:\n",
      "0.953429165286\n",
      "ROC AUC:\n",
      "0.778934596523\n"
     ]
    }
   ],
   "source": [
    "for epoch in range(0, 100):\n",
    "    print(\"epoch: %d\" %epoch)\n",
    "    mtgc.train_epoch(train_dataset_x, train_dataset.y)\n",
    "    mtgc.evaluate(train_dataset_x,\n",
    "                       valid_dataset_x,\n",
    "                       train_dataset.y,\n",
    "                       valid_dataset.y, \n",
    "                       transformer=None,\n",
    "                       batch_size=32)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
